//
//  CalendarDayCell.m
//  tttttt
//
//  Created by 张凡 on 14-8-20.
//  Copyright (c) 2014年 张凡. All rights reserved.
//



#import "CalendarDayCell.h"

@implementation CalendarDayCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView{
    
    cellBgView = [[UIView alloc ] initWithFrame:CGRectMake(0, 2, self.bounds.size.width, self.bounds.size.height - 3)];
    cellBgView.backgroundColor = [UIColor whiteColor];
    cellBgView.layer.cornerRadius =2;
    cellBgView.layer.masksToBounds=YES;
    [self addSubview:cellBgView];
    
    //选中时显示的图片
    imgview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 2, self.bounds.size.width, self.bounds.size.height - 3)];
    imgview.backgroundColor = [UIColor orangeColor];
    imgview.layer.cornerRadius =2;
    imgview.layer.masksToBounds=YES;
    [self addSubview:imgview];
    
    CGFloat textHeight = (self.bounds.size.height - 2)/3;
    
    //日期
    day_lab = [[UILabel alloc]initWithFrame:CGRectMake(3, 5, 18, textHeight)];
    day_lab.textAlignment = NSTextAlignmentCenter;
 
     [day_lab setFont:[UIFont systemFontOfSize:13]];
    [self addSubview:day_lab];
    
    tip = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, self.bounds.size.width-23,textHeight)];
    tip.textAlignment = NSTextAlignmentRight;
    [tip setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:9.0f]];
    tip.textColor = [UIColor darkGrayColor];
    

    [self addSubview:tip];
    
    //价格
    day_price = [[UILabel alloc]initWithFrame:CGRectMake(3, textHeight + 6, self.bounds.size.width - 6, textHeight-5)];
    day_price.textColor = [UIColor darkGrayColor];
    
    [day_price setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:11.0f]];
    
    day_price.textAlignment = NSTextAlignmentRight;
    [self addSubview:day_price];
}

- (void)setModel:(CalendarDayModel *)model
{
    tip.hidden = NO;
    tip.textColor = [UIColor darkGrayColor];
    
    switch (model.ticketStyle) {
        case 1:
             tip.text = @"有票";
            break;
        case 2:
            tip.text = @"已购";
            break;
        case 3:
            tip.text = @"已退";
            break;
        default:
            tip.text = @"";
            break;
    }
    
   
    
   
    switch (model.style) {
        case CellDayTypeEmpty://不显示
            [self hidden_YES];
            cellBgView.backgroundColor = [UIColor colorWithRed:241.0/255.0 green:241.0/255.0 blue:241.0/255.0 alpha:1];
            tip.hidden = YES;
            day_price.textColor = [UIColor darkGrayColor];
            break;
            
        // 不显示价格
        case CellDayTypeEmptyPrice:
            [self hidden_NO];
            tip.hidden = YES;
            cellBgView.backgroundColor = [UIColor colorWithRed:232.0/255.0 green:232.0/255.0 blue:232.0/255.0 alpha:1];
            day_lab.text = @(model.day).stringValue;
            day_lab.textColor = [UIColor lightGrayColor];
            day_price.textColor = [UIColor darkGrayColor];
            day_price.text = @"";
            imgview.hidden = YES;
            break;
        // 显示价格  
        case CellDayTypeShowPrice://周末
            [self hidden_NO];
            day_lab.text = @(model.day).stringValue;
            day_lab.textColor = COLOR_THEME1;
            day_price.textColor = [UIColor darkGrayColor];
            
            if (model.price && ![model.price isEqualToString:@""]) {
                 tip.hidden = NO;
                day_price.text = [NSString stringWithFormat:@"¥%@",model.price];
            }else{
                day_price.text = @"";
                tip.hidden = YES;
            }
            
            
            imgview.hidden = YES;
            cellBgView.backgroundColor = [UIColor whiteColor];
            break;
            
        case CellDayTypeClick://被点击的日期
            [self hidden_NO];
            day_lab.text = @(model.day).stringValue;
            day_lab.textColor = [UIColor whiteColor];
            if (model.price && ![model.price isEqualToString:@""]) {
                tip.hidden = NO;
                day_price.text = [NSString stringWithFormat:@"¥%@",model.price];
            }else{
                day_price.text = @"";
                tip.hidden = YES;
            }
            imgview.hidden = NO;
            day_price.textColor = [UIColor whiteColor];
            tip.textColor = [UIColor whiteColor];
            cellBgView.backgroundColor = [UIColor whiteColor];
            break;
        default:
            break;
    }
}

- (void)hidden_YES{
    day_lab.hidden = YES;
    day_price.hidden = YES;
    imgview.hidden = YES;
    
}


- (void)hidden_NO{
    
    day_lab.hidden = NO;
    day_price.hidden = NO;
    
}


@end
